<script>
import reportChild from "./components/reportChild.vue"
import * as echarts from "echarts";
import RealTimeClock from "./components/RealTimeClock.vue";

export default {
  mounted(){
    this.doFull();
    this.initChart();

    this.initMap();
    this.reportStatusFunction();
    this.initMaleFunction();
  },
  components:{
    RealTimeClock,
    reportChild
  },
  data(){
    return{
      chartContainer:null,


      guangxiData: [
        { name: "南宁市", value: 50, color: "rgb(244,158,45)" },
        { name: "柳州市", value: 45, color: "rgb(45,107,244)" },
        { name: "桂林市", value: 60, color: "rgb(244,46,45)" },
        { name: "梧州市", value: 30, color: "rgb(186,244,45)" },
        { name: "北海市", value: 70, color: "rgb(44,199,243)" },
        { name: "防城港市", value: 55, color: "rgb(186,244,45)" },
        { name: "钦州市", value: 40, color: "rgb(186,244,45)" },
        { name: "贵港市", value: 35, color: "rgb(44,199,243)" },
        { name: "玉林市", value: 65, color: "rgb(244,158,45)" },
        { name: "百色市", value: 50, color: "rgb(244,158,45)" },
        { name: "贺州市", value: 25, color: "rgb(243,227,44)" },
        { name: "河池市", value: 20, color: "rgb(244,46,45)" },
        { name: "来宾市", value: 10, color: "rgb(45,245,159)" },
        { name: "崇左市", value: 15, color: "rgb(44,199,243)" },
      ],
    }
  },
 methods:{
   initMaleFunction() {
     const chartDom = this.$refs.male;
     this.chartInstance = echarts.init(chartDom);

     const option = {
       tooltip: {
         trigger: 'axis',
         axisPointer: {
           type: 'line', // 默认为直线，可选为：'line' | 'shadow'
         },
       },
         legend: {
           top: '3%',  // 调整位置到顶部
           left: 'right', // 居中对齐
           textStyle: {
             color: '#FFF', // 设置文字颜色为红色
             fontSize: 12, // 设置文字大小
           },
         },
       grid: {
         left: '3%',
         right: '4%',
         bottom: '3%',
         containLabel: true,
       },
       xAxis: {
         type: 'category',
         data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
         axisLabel: {
           color: "#fff", // x轴文字颜色
           fontSize: 14,
         },
         splitLine: {
           lineStyle: {
             color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
             width: 1, // 网格线宽度
             type: "dashed", // 可选: 'solid' 或 'dashed'
           },
         }
       },
       yAxis: {
         type: 'value',
         axisLabel: {
           color: "#fff", // x轴文字颜色
           fontSize: 14,
         },
         splitLine: {
           lineStyle: {
             color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
             width: 1, // 网格线宽度
             type: "dashed", // 可选: 'solid' 或 'dashed'
           },
         }
       },
       series: [
         {
           name: '男生',
           type: 'bar',
           stack: '总量',
           emphasis: {
             focus: 'series',
           },
           itemStyle: {
             color: {
               type: 'linear',
               x: 0,
               y: 0,
               x2: 0,
               y2: 1,
               colorStops: [
                 { offset: 0, color: '#83bff6' }, // 起始颜色
                 { offset: 1, color: '#188df0' }, // 结束颜色
               ],
             },
           },
           data: [120, 132, 101, 134, 90, 230, 210],
         },
         {
           name: '女生',
           type: 'bar',
           stack: '总量',
           emphasis: {
             focus: 'series',
           },
           itemStyle: {
             color: {
               type: 'linear',
               x: 0,
               y: 0,
               x2: 0,
               y2: 1,
               colorStops: [
                 { offset: 0, color: '#f9a825' },
                 { offset: 1, color: '#f57f17' },
               ],
             },
           },
           data: [220, 182, 191, 234, 290, 330, 310],
         },

       ],
     };

     this.chartInstance.setOption(option);
   },
   reportStatusFunction() {
     const chartDom = this.$refs.reportStatus;
     this.chart = echarts.init(chartDom);

     const option = {
       tooltip: {
         trigger: "axis",
         axisPointer: {
           type: "shadow",
         },
       },

       legend: {
         data: ["已报道", "未报道"],
         bottom: '5%',  // 调整位置到顶部
         left: 'center', // 居中对齐
         textStyle: {
           color: '#FFF', // 设置文字颜色为红色
           fontSize: 12, // 设置文字大小
         },
       },
       xAxis: {
         type: "category",
         data: ["数据1", "数据2", "数据3", "数据4"],
         splitLine: {
           lineStyle: {
             color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
             width: 1, // 网格线宽度
             type: "dashed", // 可选: 'solid' 或 'dashed'
           },
         },
         axisLabel: {
           color: "#fff", // x轴文字颜色
           fontSize: 14,
           fontWeight:'bold'
         },
       },
       yAxis: {
         type: "value",
         splitLine: {
           lineStyle: {
             color: "rgba(255, 255, 255, 0.2)",// // 设置网格线为浅灰色且透明
             width: 1, // 网格线宽度
             type: "dashed", // 可选: 'solid' 或 'dashed'
           },
         },
         axisLabel: {
           color: "#fff", // x轴文字颜色
           fontSize: 14,
           fontWeight:'bold'
         },
       },
       series: [
         {
           name: "已报道",
           type: "bar",
           barWidth: 20, // 柱子的宽度
           itemStyle: {
             color: {
               type: "linear",
               x: 0,
               y: 0,
               x2: 0,
               y2: 1,
               colorStops: [
                 { offset: 0, color: "#83bff6" }, // 渐变起始色
                 { offset: 1, color: "#188df0" }, // 渐变结束色
               ],
             },
           },
           data: [120, 200, 150, 80],
         },
         {
           name: "未报道",
           type: "bar",
           barWidth: 20, // 确保柱子的宽度一致
           itemStyle: {
             color: {
               type: "linear",
               x: 0,
               y: 0,
               x2: 0,
               y2: 1,
               colorStops: [
                 { offset: 0, color: "#ff7f50" }, // 渐变起始色
                 { offset: 1, color: "#ff4500" }, // 渐变结束色
               ],
             },
           },
           data: [90, 140, 110, 130],
         },
       ],
     };

     this.chart.setOption(option);
   },
   async initMap() {
     const mapContainer = document.getElementById("guangxi-map");
     const chart = echarts.init(mapContainer);

     // 加载广西 GeoJSON 数据
     const guangxiGeoJSON = await fetch("https://geo.datav.aliyun.com/areas_v3/bound/450000_full.json").then((res) =>
       res.json()
     );

     // 注册广西地图
     echarts.registerMap("guangxi", guangxiGeoJSON);

     // 配置项
     const option = {
       tooltip: {
         trigger: "item",
         formatter: (params) => `${params.name}<br/>数值: ${params.value || 0}`,
       },
       geo: {
         map: "guangxi",
         label: {
           show: false,
         },
         itemStyle: {
           areaColor: "rgba(0, 0, 0, 0)", // 移除默认区域颜色
           borderColor: "#333",
         },

       },
       series: [
         {
           type: "map",
           map: "guangxi",
           label: {
             show: true, // 显示城市名称和数值
             formatter: (params) => `${params.name}\n${params.value || 0}`,
             fontSize: 13,
             position: "inside",
           },
           itemStyle: {
             areaColor: "#ccc", // 默认颜色
             borderColor: "#ffffff",
           },
           emphasis: {
             label: {
               show: true,
               color: "#fff",
             },
             itemStyle: {
               areaColor: "#006edd",
             },
           },
           data: this.guangxiData.map((item) => ({
             name: item.name,
             value: item.value,
             itemStyle: {
               areaColor: item.color, // 自定义色块
             },
           })),
         },
       ],
     };

     // 渲染地图
     chart.setOption(option);
   },
   doFull() {
     this.$store.dispatch('app/toggleSideBarHide', true);
     document.querySelector('.navbar').style.display = "none";
     document.querySelector('.tags-view-container').style.display = "none";
   },
   notFull() {
     this.$store.dispatch('app/toggleSideBarHide', false);
     document.querySelector('.navbar').style.display = "block";
     document.querySelector('.tags-view-container').style.display = "block";
   },
   initChart() {
     // 获取图表容器
     // const chartDom = document.getElementById('chartContainer');
     const chartDom  = this.$refs.chartContainer
     console.log(chartDom)
     const myChart = echarts.init(chartDom);

     // 图表配置项
     const option = {
       tooltip: {
         trigger: "axis",
         axisPointer: {
           type: "shadow",
         },
       },
       xAxis: {
         type: "value",
         boundaryGap: [0, 0.01],
         axisLabel: {
           color: "#fff", // x轴文字颜色
         },
         axisLine: {
           show: false, // 隐藏 x 轴的轴线
         },
         splitLine: {
           lineStyle: {
             color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
             width: 1, // 网格线宽度
             type: "dashed", // 可选: 'solid' 或 'dashed'
           },
         }
       },
       yAxis: {
         type: "category",
         data: ["类别A", "类别B", "类别C", "类别D", "类别E"],
         axisLabel: {
           color: "#fff", // x轴文字颜色
           fontSize: 15,
           fontWeight:'bold'
         },
         axisLine: {
           show: false, // 隐藏 x 轴的轴线
         },
         splitLine: {
           lineStyle: {
             color: "rgba(255, 255, 255, 0.2)", // 设置网格线为浅灰色且透明
             width: 1, // 网格线宽度
             type: "dashed", // 可选: 'solid' 或 'dashed'
           },
         }
       },
       series: [
         {
           name: "数据",
           type: "bar",
           data: [120, 200, 150, 80, 70],
           itemStyle: {

             color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
               { offset: 0, color: "#00D4FF" },
               { offset: 1, color: "#007BFF" },
             ]),
           },
           barWidth: "40%",
           label: {
             show: true,
             position: "right", // 显示在柱子顶部
             color: "#fff", // 数值颜色
             fontSize: 12, // 数值字体大小
           },
         },
       ],
     };

     // 设置图表选项
     myChart.setOption(option);

     // 监听窗口大小变化，自动调整图表大小
     window.addEventListener("resize", () => {
       myChart.resize();
     });
   },
 }
}
</script>

<template>
<div class="main-box-report">
  <div class="top-title">
    <img src = "./images/bt.svg" alt = "title">
  </div>
  <div class="time-show">
    <real-time-clock />
  </div>
  <div class="quit-button" @click="notFull()">
    <img src = "./images/quit.svg" alt = "quit">
  </div>
  <div class="head-box">
    <report-child title="各院系新生缴费人数" >
      <div  class="Container" ref="chartContainer"></div>
    </report-child>
    <report-child title="录取地图">
      <div id="guangxi-map" style="width: 80%; height: 600px;position: relative;left:-100px;top:-80px;z-index: 999"></div>
      <div class="map-table">
        <div class="head">
          <div>录取城市</div>
          <div>录取人数</div>
          <div>报道人数</div>
        </div>
        <div v-for="item in 13">
          <div>桂林市</div>
          <div>282</div>
          <div>260</div>
        </div>
      </div>
    </report-child>
  </div>
  <div class="between-box">
    <report-child title="目前报道人数">
      <div class="report-people">
        <div v-for="item in 6">
          <div>6716</div>
          <div>在线报道人数</div>
        </div>
      </div>
    </report-child>
    <report-child title="学院报道情况">
      <div class="switch_button">
        <div class="active">里建校区</div>
        <div>里建校区</div>
      </div>
      <div ref="reportStatus" style="width: 110%; height: 350px"></div>
    </report-child>
    <report-child title="最新报到同学">
      <div class="new-report-student">
        <div>
          <div>报道学生</div>
          <div>报道学院</div>
          <div>报道同学</div>
        </div>
        <div v-for="item in 7">
          <div>张三林</div>
          <div>自动化工程学院</div>
          <div>09/16  16:47</div>
        </div>
      </div>
    </report-child>
    <report-child title="学院男女比例">
      <div class="switch_button">
        <div class="active">里建校区</div>
        <div>里建校区</div>
      </div>
      <div ref="male" style="width: 110%; height: 320px;position: relative;left:-20px;"></div>
    </report-child>
  </div>
  <div class="bottom-box">
    <report-child title="宿舍预警">
    <div class="warning-main-box">
      <div class="warning-item" v-for="item in 8">
        <div>里建校区·和园</div>
        <div>土木建筑工程学院</div>
        <div>782</div>
        <div>
          <img src = "./images/house.svg" alt = "house-icon">
          入住人数</div>
         <div>
           <el-progress
             :stroke-width="24"
             :percentage="70"
             define-back-color	="#BFFFA0"
             color="#50AC24"
             :show-text="false"
           ></el-progress>
         </div>
        <div>剩余床位：70</div>

      </div>
    </div>
    </report-child>
  </div>
</div>
</template>

<style scoped lang = "scss">
.warning-main-box{
  display: grid;
  grid-template-columns: repeat(8,1fr);
  padding-top:28px;
  column-gap: 10px;
  .warning-item{
    padding: 10px 10px;
    height: 250px;
    background: linear-gradient(180deg, rgba(1, 104, 180, 0.15) 1%, rgba(81, 145, 225, 0.15) 99%);
    border-radius: 10px;

    box-sizing: border-box;
    border: 1px solid #5191E1;
    text-align: center;
    display: grid;
    column-gap: 10px;
    position: relative;
    >div:nth-child(1){
      font-size: 20px;
      font-weight: bold;
    }
    >div:nth-child(2){
      font-size: 16px;
    }
    >div:nth-child(3){
      font-size: 40px;
      font-weight: bold;
    }
    >div:nth-child(4){
      img{
        position: relative;
        top:3px;
      }
    }
    >div:nth-child(5){
      width: 100%;
    }
  >div:nth-child(6){
    position: absolute;
    bottom:30px;
    left: 23px;
    font-size: 14px;
    font-weight: bold;
  }
  }
}

.new-report-student{
  display: grid;
  padding-top: 20px;
  width: 120%;
  position: relative;
  left: -35px;
  >div:nth-child(1){
    font-size: 18px;
    color: rgba(255, 255, 255, 0.5);
  }
  >div{
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    text-align: center;
    line-height:35px;
  }
}
.switch_button{
  display: flex;
  position: absolute;
  top: 48px;
  column-gap: 10px;
  //width:420px;
  .active{
    background: linear-gradient(270deg, #00D4FF 0%, #007BFF 100%) !important;

    box-sizing: border-box;
    border: 1px solid #5191E1;
  }
  >div{
    background: linear-gradient(180deg, rgba(1, 104, 180, 0.15) 1%, rgba(81, 145, 225, 0.15) 99%);
    width: 100px;
    height: 28px;
    line-height:27px;
    box-sizing: border-box;
    border: 1px solid #5191E1;
    font-size: 14px;
    text-align: center;

    position: relative;
    cursor: pointer;

  }
}
.report-people{
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 1fr 1fr;
  row-gap: 30px;

  position: relative;
  top:100%;
  transform: translateY(-10%);
  >div{
    text-align: center;
    >div:nth-child(1){
      font-size: 40px;
      font-weight: bold;
      font-family: Tomorrow;

    }
    >div:nth-child(2){
      padding-top: 5px;
    }
  }
}
.map-table{
  position: absolute;
  width: 400px;
  top: 50px;
  right: 60px;
  padding: 10px 20px;
  box-sizing: border-box;

  display: grid;
  row-gap: 10px;
  >div:nth-child(1){
    font-weight: bold;
    font-size: 17px;
  }
  >div{
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    column-gap: 20px;
    text-align: center;
    line-height: 20px;
  }

  background: linear-gradient(180deg, rgba(1, 104, 180, 0.15) 1%, rgba(81, 145, 225, 0.15) 99%);

  box-sizing: border-box;
  border: 1px solid #5191E1;

  box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.15);
}
.top-title{
  img{
    position: relative;
    width: 100%;
  }
}
.main-box-report{
  width: 100%;
  height: 1460px;
  background-image:url("./images/background.png");
  background-size: 100% auto;

  color: white;
}
// grid 三栏布局
.head-box{
  padding: 20px 10px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 35% 65%;
  > div{
    height: 500px;
  }

}
.between-box{
  padding: 5px 10px 20px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 25% 25% 25% 25%;
  > div{
    height: 380px;
  }
}
.bottom-box{
  width: 100%;
  margin: 10px;
  padding: 0px 10px;
  position: relative;
  left: -10px;
  > div{
    height: 380px;
  }
}


.Container{
  width: 110%; height: 500px;position: relative;left:-20px;top:-20px;
}

.time-show{
  position: absolute;
  top:23px;
  left:20px;
}
.quit-button{
  position: absolute;
  right:16px;
  top:10px;
  cursor: pointer;
  transition: all 0.3s;
}
.quit-button:hover{
  opacity: 0.6;
}
</style>
